package com.cloud.bssp.admin.wanda.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bssp.admin.wanda.entity.EmployeeAttendanceDO;
import com.cloud.bssp.admin.wanda.dto.EmployeeAttendanceDTO;
import com.cloud.bssp.admin.wanda.service.EmployeeAttendanceService;
import com.cloud.bssp.admin.wanda.convert.EmployeeAttendanceDoConvert;
import com.cloud.bssp.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description: 员工
 * Create Date: 2021-07-08T15:36:44.712
 * Modified By：<br>
 * Modified Date：<br>
 * Why & What is modified：<br>
 *
 * @author weirx
 * @version 1.0
 */
@Api(tags = "员工")
@RestController
@RequestMapping("/employeeAttendance")
@AllArgsConstructor
public class EmployeeAttendanceController {

    /**
     * EmployeeAttendanceService
     */
    private EmployeeAttendanceService employeeAttendanceService;

    /**
     * 分页列表
     * @param employeeAttendanceDTO
     * @return
     */
    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public R pageList(@RequestBody EmployeeAttendanceDTO employeeAttendanceDTO) {
        QueryWrapper<EmployeeAttendanceDO> queryWrapper = new QueryWrapper<>(EmployeeAttendanceDoConvert.dtoToDo(employeeAttendanceDTO));
        Page<EmployeeAttendanceDO> page = new Page<>(employeeAttendanceDTO.getPage(), employeeAttendanceDTO.getLimit());
        Page<EmployeeAttendanceDO> pageList = employeeAttendanceService.page(page, queryWrapper);
        return R.success(EmployeeAttendanceDoConvert.pageConvert(pageList));
    }

    /**
     * list列表
     * @param employeeAttendanceDTO
     * @return
     */
    @ApiOperation(value = "list列表")
    @PostMapping("/list")
    public R list(@RequestBody EmployeeAttendanceDTO employeeAttendanceDTO) {
        QueryWrapper<EmployeeAttendanceDO> queryWrapper = new QueryWrapper<>(EmployeeAttendanceDoConvert.dtoToDo(employeeAttendanceDTO));
        List<EmployeeAttendanceDO> employeeAttendanceList = employeeAttendanceService.list(queryWrapper);
        return R.success(EmployeeAttendanceDoConvert.listConvert(employeeAttendanceList));
    }

    /**
     * 根据主键查询
     * @param id
     * @return
     */
    @ApiOperation(value = "根据主键查询")
    @GetMapping("/info/getById")
    public R info(@RequestParam("id")Long id) {
            EmployeeAttendanceDO employeeAttendance = employeeAttendanceService.getById(id);
        return R.success(EmployeeAttendanceDoConvert.doToDto(employeeAttendance));
    }

    /**
     * 新增
     * @param employeeAttendanceDTO
     * @return
     */
    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public R save(@RequestBody EmployeeAttendanceDTO employeeAttendanceDTO) {
        boolean flag = employeeAttendanceService.save(EmployeeAttendanceDoConvert.dtoToDo(employeeAttendanceDTO));
        if (flag) {
            return R.success();
        }
        return R.failed();
    }

    /**
     * 更新
     * @param employeeAttendanceDTO
     * @return
     */
    @ApiOperation(value = "更新")
    @PostMapping("/update")
    public R update(@RequestBody EmployeeAttendanceDTO employeeAttendanceDTO) {
        boolean flag = employeeAttendanceService.updateById(EmployeeAttendanceDoConvert.dtoToDo(employeeAttendanceDTO));
        if (flag) {
            return R.success();
        }
        return R.failed();
    }
}